package com.nkzy.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

//WebInitializer代替web.xml,是Tomcat容器初始化
public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    //获取Spring配置类，根据它创建Spring父容器
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }
    //获取SpringMVC的配置类
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMVCConfig.class};
    }
    //指定前端控制器请求路径：SpringMVC前端控制器
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
    //指定字符编码
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter filter=new CharacterEncodingFilter();
        filter.setEncoding("utf-8");
        return new Filter[]{filter};
    }
    //指定文件上传的大小
}

